package com.stedu.service.impl;

import com.stedu.bean.CustomUser;
import com.stedu.bean.SysUser;
import com.stedu.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.TreeSet;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private SysUserService sysUserService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser byUsername = sysUserService.getByUsername(username);
        if (byUsername==null){
            throw new UsernameNotFoundException("用户名或密码错误，请重新登录");
        }
        return new CustomUser(byUsername, new TreeSet<>());
    }
}
